package com.hxkj.controller.wechat;

import com.hxkj.domain.po.*;
import com.hxkj.service.NavigationService;
import com.hxkj.service.wechat.AppletAgentService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 * 业务员关联小程序对外接口
 * <p>
 * Created by chenfangzhou on 2018/6/6.
 */
@RestController
@RequestMapping("/user")
public class AppletAgentController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AppletAgentController.class);

    @Autowired
    private AppletAgentService appletAgentService;




    /**
     * 业务员关联小程序
     *
     * @param appletAgent
     * @throws Exception
     */
    @RequiresPermissions("agent:add")
    @RequestMapping(value = "/addapplettouser", method = RequestMethod.POST)
    public ResultMessageStruct addAppletToUser(@ModelAttribute AppletAgent appletAgent) throws Exception {
        return appletAgentService.addAppletToUser(appletAgent);
    }

    /**
     * 业务员小程序取消分配
     *
     * @param appletAgent
     * @throws Exception
     */
    @RequiresPermissions("agent:modify")
    @RequestMapping(value = "/removeapplettouser", method = RequestMethod.POST)
    public ResultMessageStruct removeAppletToUser(@ModelAttribute AppletAgent appletAgent) throws Exception {
        return appletAgentService.removeAppletToUser(appletAgent);
    }

    /**
     * 查询已关联自媒体角色的用户
     */
    @RequiresPermissions("agent:view")
    @RequestMapping(value = "/getagentlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<AuthUserAgent>> getAgentList(@ModelAttribute AuthUserAgent authUserAgent, @ModelAttribute PageTo pageParam) throws Exception{
        return () -> appletAgentService.getAgentList(authUserAgent == null ? new AuthUserAgent() : authUserAgent, pageParam);
    }
    /**
     * 查询自媒体业务员未分配/已分配的小程序
     */
    @RequiresPermissions("agent:view")
    @RequestMapping(value = "/getassignapplet", method = RequestMethod.POST)
    public Callable<ResultPageStruct<Applet>> getAppletList(@ModelAttribute AppletAgent appletAgent,@ModelAttribute PageTo pageParam) throws Exception{
        return () -> appletAgentService.getAppletList(appletAgent == null ? new AppletAgent() : appletAgent, pageParam);
    }

    /**
     * 保存小程序的最大推送文章
     *
     * @param appletAgent
     * @throws Exception
     */
    @RequiresPermissions("agent:add")
    @RequestMapping(value = "/saveappletarticle", method = RequestMethod.POST)
    public ResultMessageStruct saveAppletArticle(@ModelAttribute AppletAgent appletAgent) throws Exception {
        return appletAgentService.saveAppletArticle(appletAgent);
    }

}
